﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

using MyDHServer.Compontents;
using MyDHServer.DataAccess;
namespace MyDHServer.Contorls
{
    public class postlist:blogSkinControl
    {
        Repeater Posts = null;

        public postlist()
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
                this.DataBind();
            base.OnLoad(e);
        }

        public override void DataBind()
        {
            base.DataBind();
            List<DHBlog> myBlogs=Blogs.GetBlogs();
            Posts.DataSource = myBlogs;
            Posts.DataBind();
        }
        protected override void AttachChildControls()
        {
            Posts = FindControl("Posts") as Repeater;
            Posts.ItemDataBound+=new RepeaterItemEventHandler(Posts_ItemDataBound);
        }


        void Posts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DHBlog blog = e.Item.DataItem as DHBlog;

            if (blog == null)
                return;

            switch (e.Item.ItemType)
            {
                case ListItemType.Item:
                case ListItemType.AlternatingItem:
                    HyperLink TitleLink = (HyperLink)e.Item.FindControl("TitleLink");
                    Literal body = (Literal)e.Item.FindControl("body");

                    TitleLink.Text = blog.title;
                    body.Text = blog.context;
                    break;
            }
        }
    }
}
